/**
 * 
 */
package com.cqcis.uip.module.salary.oper.service.impl.employe;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cqcis.uip.module.salary.oper.SalaryConstants;
import com.cqcis.uip.module.salary.oper.dao.SalarylevelDao;
import com.cqcis.uip.module.salary.oper.dao.jdbc.ContractJdbcDao;
import com.cqcis.uip.module.salary.oper.domain.Employe;
import com.cqcis.uip.module.salary.oper.domain.Salary;
import com.cqcis.uip.module.salary.oper.domain.SalaryCourseTimesDetail;
import com.cqcis.uip.module.salary.oper.domain.SalaryCourseTimesManagerDetail;
import com.cqcis.uip.module.salary.oper.domain.SalaryMain;
import com.cqcis.uip.module.salary.oper.domain.SalaryTCDetail;
import com.cqcis.uip.module.salary.oper.domain.SalaryTrusteeshipDetail;
import com.cqcis.uip.module.salary.oper.domain.Salarylevel;
import com.cqcis.uip.module.salary.oper.service.CourseService;
import com.cqcis.uip.module.salary.oper.service.ProcessEmployeService;
import com.cqcis.uip.module.salary.oper.service.RatioService;
import com.cqcis.uip.module.salary.oper.service.TrusteeshipService;
import com.cqcis.uip.module.salary.oper.service.WelfareService;
import com.cqcis.uip.module.salary.oper.service.impl.ProcessServiceImpl;

/**
 * @author 李世军
 *
 * 创建于 2012-3-20 下午04:56:26
 */
public class ProcessAllServiceImpl implements ProcessEmployeService {
	@SuppressWarnings("unused")
	private static Log log = LogFactory.getLog(ProcessServiceImpl.class);
	private WelfareService welfareService ;
	private RatioService ratioService ;
	private SalarylevelDao salarylevelDao ;
	private CourseService courseService ;
	private TrusteeshipService trusteeshipService ;
	private ContractJdbcDao contractJdbcDao ;
	
	
	public void setContractJdbcDao(ContractJdbcDao contractJdbcDao) {
		this.contractJdbcDao = contractJdbcDao;
	}
	public void setTrusteeshipService(TrusteeshipService trusteeshipService) {
		this.trusteeshipService = trusteeshipService;
	}
	public void setCourseService(CourseService courseService) {
		this.courseService = courseService;
	}
	public void setWelfareService(WelfareService welfareService) {
		this.welfareService = welfareService;
	}
	public void setRatioService(RatioService ratioService) {
		this.ratioService = ratioService;
	}
	public void setSalarylevelDao(SalarylevelDao salarylevelDao) {
		this.salarylevelDao = salarylevelDao;
	}

	/* (non-Javadoc)
	 * @see com.cqcis.uip.module.salary.oper.service.ProcessReferService#process(com.cqcis.uip.module.salary.oper.domain.Employe)
	 */
	public Salary process(Employe e) {
		Salary salary = new Salary() ;
		SalaryMain main = new SalaryMain() ;
		List<SalaryTCDetail> details = new ArrayList<SalaryTCDetail>() ;
		List<SalaryCourseTimesDetail> courseDetails = new ArrayList<SalaryCourseTimesDetail>() ;
		List<SalaryTrusteeshipDetail> salaryTrusteeshipDetails = new ArrayList<SalaryTrusteeshipDetail>() ;
		List<SalaryCourseTimesManagerDetail> salaryCourseTimesManagerDetails = new ArrayList<SalaryCourseTimesManagerDetail>() ;
		
		// 员工信息
		main.setEmploye_id(e.getId()) ;
		
		// 薪档工资
		Salarylevel salaryLevel = salarylevelDao.get(e.getSalary_grade(), e.getPosition_level()) ;
		if(salaryLevel==null){
			main.setSalarylevel_id(SalaryConstants.SALARY_LEVEL_NONE) ;
			main.setRemark(main.getRemark()+"|薪档未配置") ;
		}else{
			main.setSalarylevel_id(salaryLevel.getId()) ;
		}
		
		
		// 福利工资
		welfareService.setSalaryMain(e, main) ;
		
		// 全勤奖(考勤界面) 各项汇总
		main.setMonthfee(salarylevelDao.getMonthFee(e.getId())) ;
		
		// 合同业绩提成工资
		ratioService.setSalary(e, main, details) ;
		
		// 教师-学管师 课时提成
		courseService.setSalary(e, main, courseDetails, salaryCourseTimesManagerDetails) ;
		
		// 教师托管提成
		trusteeshipService.setSalary(e, main, salaryTrusteeshipDetails) ;
		
		// 邀约提成
		main.setCall_fee(contractJdbcDao.getCallFee(e.getId())) ;
		
		// 绩效考核分数
		main.setPerformance_no(salarylevelDao.getFormanceNo(e.getId())) ;
		
		// 保险扣款及个税
		main.setInsure_fee(salarylevelDao.getInsure(e.getId())) ; 
		
		
		
		salary.setSalaryMain(main) ;
		salary.setSalaryTCDetails(details) ;
		salary.setSalaryCourseTimesDetails(courseDetails) ;
		salary.setSalaryTrusteeshipDetails(salaryTrusteeshipDetails) ;
		salary.setSalaryCourseTimesManagerDetail(salaryCourseTimesManagerDetails) ;
		return salary ;
	}

}
